package com.hkrt.demo.di.module

import android.support.v4.app.FragmentManager
import android.support.v7.app.AppCompatActivity
import android.view.LayoutInflater
import dagger.Module
import dagger.Provides
import com.hkrt.demo.data.cache.MemoryCache
import com.hkrt.demo.data.mapper.Mapper
import com.hkrt.demo.data.network.AuthApiService
import com.hkrt.demo.data.network.HkrtApiService
import com.hkrt.demo.data.network.UserApiService
import com.hkrt.demo.data.pref.Preferences
import com.hkrt.demo.data.repository.HkrtDataRepository
import com.hkrt.demo.data.repository.UserDataRepository
import com.hkrt.demo.di.scope.PerActivity
import com.hkrt.demo.domain.repository.HkrtRepository
import com.hkrt.demo.domain.repository.UserRepository

/**
* @author  Chenjinguang
* @date 31.07.2017.
*/
@Module
class ActivityModule(private val activity: AppCompatActivity) {

    @PerActivity
    @Provides
    fun providesActivity(): AppCompatActivity = activity

    @PerActivity
    @Provides
    fun providesLayoutInflater(activity: AppCompatActivity): LayoutInflater =
            LayoutInflater.from(activity)

    @PerActivity
    @Provides
    fun providesFragmentManager(activity: AppCompatActivity): FragmentManager =
            activity.supportFragmentManager

    @PerActivity
    @Provides
    fun provideShotRepository(hkrtApiService: HkrtApiService, memoryCache: MemoryCache, mapper: Mapper): HkrtRepository
            = HkrtDataRepository(hkrtApiService, memoryCache, mapper)

    @PerActivity
    @Provides
    fun provideUserRepository(authApiService: AuthApiService,
                              userApiService: UserApiService,
                              preferences: Preferences,
                              memoryCache: MemoryCache,
                              mapper: Mapper): UserRepository
            = UserDataRepository(authApiService, userApiService, preferences, memoryCache, mapper)

}